<?php

namespace App\Kuafu\User\Service;

use App\Exceptions\BaseException;
use App\Kuafu\Base\Service\BaseService;
use Illuminate\Support\Facades\Cache;
use Psr\SimpleCache\InvalidArgumentException;

class CacheService extends BaseService
{

    /**
     * @param object $params
     * @return array|void
     * @throws BaseException
     */
    public static function rmCache(object $params)
    {
        try {
            $redis = Cache::store("redis");
            return [
                "rmCacheResult" => collect($params->cacheKeys)->map(function ($cacheKey) use ($redis) {
                    $keyExists = $redis->has($cacheKey);
                    return [
                        "cacheKey"  => $cacheKey,
                        "keyExists" => $keyExists,
                        "result"    => $keyExists && Cache::store("redis")->delete($cacheKey)
                    ];
                })->toArray()
            ];
        } catch (\Exception $exception) {
            handleException($exception, "移除缓存失败 - {$params->cacheKey}");
        }
    }

}
